package com.itheima.info.manager.service;

import com.itheima.info.manager.Factory.StudentDaoFactory;
import com.itheima.info.manager.dao.BaseStudentDao;
import com.itheima.info.manager.dao.StudentDao;
import com.itheima.info.manager.domain.Student;

/*
业务员类
 */
public class StudentService {

    private BaseStudentDao dao = StudentDaoFactory.getDao();

//添加方法
    public boolean addStudent(Student stu) {
        //添加学生功能
        return dao.addStudent(stu);

    }
//查找方法
    public Student[] findAllStudent() {
        Student[] stus = dao.findAllStudent();
        //标记位
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return stus;
        } else {
            return null;
        }

    }

    //业务员中修改学生
    public void updateStudent(String updateId, Student stu) {
        dao.updateStudent(updateId, stu);
    }

    public boolean deleteStudent(String delId) {
        return dao.deleteStudent(delId);
    }

    public boolean isExists(String updateId) {
        int index = dao.getIndex(updateId);
        //返回一个true说明dao中不存在该学号;反之存在该学号
        return index == -1;
    }
}
